<template>
  <div class="movie-card">
    <img :src="BASE_URL + movie.posterUrl" :alt="movie.movieName" class="movie-poster">
    <div class="movie-info">
      <h3 class="movie-name">{{ movie.movieName }}</h3>
      <div class="movie-score" v-if="movie.score">
        <span class="score">{{ movie.score }}</span>
        <span class="score-text">分</span>
      </div>
      <div class="movie-director">导演：{{ movie.director }}</div>
      <div class="movie-actors">主演：{{ movie.cast }}</div>
      <div class="movie-showtime">上映时间：{{ movie.releaseYearDate }}</div>
      <button 
        class="buy-btn"
        @click="handleBuy"
        :class="{ 'coming-soon': currentTab === 'coming' }"
      >
        {{ buyButtonText }}
      </button>
    </div>
  </div>
</template>

<script setup>
import { computed } from 'vue'
import { useRouter } from 'vue-router'

const router = useRouter()

const props = defineProps({
  movie: {
    type: Object,
    required: true
  },
  currentTab: {
    type: String,
    default: 'now'
  }
})

const buyButtonText = computed(() => 
  props.currentTab === 'coming' ? '预售' : '购票'
)

const handleBuy = () => {
  router.push({
    name: 'cinema',
    query: {
      movieId: props.movie.id
    }
  })
}
</script>

<style scoped>
.movie-card {
  background: white;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 2px 12px rgba(0,0,0,0.1);
  transition: transform 0.3s ease;
}

.movie-card:hover {
  transform: translateY(-5px);
}

.movie-poster {
  width: 100%;
  height: 250px;
  object-fit: cover;
}

.movie-info {
  padding: 12px;
}

.movie-name {
  margin: 0;
  font-size: 16px;
  font-weight: bold;
  margin-bottom: 8px;
}

.movie-score {
  color: #ff5f16;
  margin-bottom: 8px;
}

.score {
  font-size: 18px;
  font-weight: bold;
}

.score-text {
  font-size: 14px;
}

.movie-director,
.movie-actors,
.movie-showtime {
  font-size: 12px;
  color: #666;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.buy-btn {
  width: 100%;
  padding: 8px;
  background: #ff5f16;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  margin-top: 12px;
  transition: background-color 0.3s ease;
}

.buy-btn:hover {
  background: #ff4500;
}

.buy-btn.coming-soon {
  background: #2db7f5;
}

.buy-btn.coming-soon:hover {
  background: #0098f7;
}
</style> 